<?php
require_once '../common.php';
require_once 'function/Index.class.php';
require_once 'function/Login.class.php';

/**
 * <h2>判断是否已经登录</h2>
 *
 * @return boolean
 */
function isAdminLogin() {
	if (! isset ( $_SESSION ['admin'] ) || $_SESSION ['admin'] !== true) {
		return false;
	}
	return true;
}

/**
 * <h2>跳转到后台首页</h2>
 */
function forwardToHome() {
	header ( 'Location:' . CONSOLE_BASE );
	exit ();
}

$request = new Request ();
$a = $request->getGet ( 'a' );
// 检查是不是管理员
try {
	if (! isAdminLogin ()) {
		throw new ExceptionEx ( 'not login' );
	}
	// TODO 检查超时
} catch ( ExceptionEx $e ) {
	if (strtolower ( $a ) != 'login') {
		header ( "Location: /manage/?a=login" );
		exit ();
	}
}

if (! class_exists ( ucfirst ( $a ) )) {
	$a = 'Index';
}
$action = new $a ();

$m = $request->getGet ( 'm' );
if (empty ( $m ) || ! method_exists ( $action, $m )) {
	$method = 'index';
} else {
	$method = $m;
}

$action->$method ();